﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Model.User;
using Enterprise.Infrastructure;
namespace Enterprise.Data.User
{
    /// <summary>
    /// 用户角色表操作
    /// </summary>
    public class UserRoleData
    {
        /// <summary>
        ///  用户角色数据列表
        /// </summary>
        /// <returns></returns>
        public List<UserRoleEntity> UserRoleList()
        {
            List<UserRoleEntity> list = new List<UserRoleEntity>();
            string cmd = "Select * from SYS_USERROLE";
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                UserRoleEntity entity = new UserRoleEntity();
                if (!Convert.IsDBNull(dr["ROLEID"])) entity.ROLEID = Convert.ToInt32(dr["ROLEID"]);
                if (!Convert.IsDBNull(dr["USERID"])) entity.USERID = Convert.ToInt32(dr["USERID"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        public List<UserRoleEntity> UserRoleList(int UserId)
        {
            List<UserRoleEntity> list = new List<UserRoleEntity>();
            string cmd = "Select * from SYS_USERROLE where USERID="+UserId;
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                UserRoleEntity entity = new UserRoleEntity();
                if (!Convert.IsDBNull(dr["ROLEID"])) entity.ROLEID = Convert.ToInt32(dr["ROLEID"]);
                if (!Convert.IsDBNull(dr["USERID"])) entity.USERID = Convert.ToInt32(dr["USERID"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        /// <summary>
        /// 用户角色数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void UserRoleExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }
    }
}
